#ifndef _CLIUTIL_H
#define _CLIUTIL_H

#include <string.h>
#include <stdio.h>
#include <vector>
#include <iconv.h>
#include "cli.h"

using namespace std;
using namespace cli;

#ifdef __cplusplus
extern "C"{
#endif

extern string& trim(string &s);
extern void split(string& s, string& delim, vector<string>* ret); 
extern bool getCnString(string keyName, string &keyVal );


#ifdef __cplusplus
}
#endif

// 代码转换操作类
class CodeConverter
{
    private:
        iconv_t cd;
        char inbuf_m[MAX_CMD_LENGTH];
    public:
    
    CodeConverter(const char *from_charset,const char *to_charset) 
    {
        cd = iconv_open(to_charset,from_charset);
    }
    ~CodeConverter() {
        iconv_close(cd);
    }
    
    // 转换输出
    int convert(const char *inbuf,int inlen,char *outbuf,int outlen) 
    {
        memset(&inbuf_m[0], 0, MAX_CMD_LENGTH);
        memset(outbuf, 0, outlen);
        memcpy(&inbuf_m[0], inbuf, inlen);

        char *a = &inbuf_m[0];
        char **pin = &a;
        char **pout = &outbuf;
    
        return iconv(cd, pin, (size_t *)&inlen, pout, (size_t *)&outlen);
    }
};


#endif

